var PATH_PREFIX = "";
function setPathPrefix(path){
	PATH_PREFIX =  path;
}
var HOT_NEWS_ADD = function(){
	this.init();
};
/**
 * 初始化方法
 */
HOT_NEWS_ADD.prototype.init = function(){
	var self = this;
	self.expand();
	
	WASP_WIDGET.triggerInstSelect("#managerId");
	$('#managerId').change( function() {
		$(this).valid && $(this).valid();
	});
	
	$("#prjStatus").select2({placeholder: "产品状态"});
	$("#prjStatus").on("change", function(){
		$(this).valid && $(this).valid();
	});

	$("#runMode").select2({placeholder: "运作模式"});
	$("#runMode").on("change", function(){
		$(this).valid && $(this).valid();
	});
	
	$("#profitMode").select2({placeholder: "收益模式"});
	$("#profitMode").on("change", function(){
		$(this).valid && $(this).valid();
	});
	
	$("#riskLevel").select2({placeholder: "风险等级"});
	$("#riskLevel").on("change", function(){
		$(this).valid && $(this).valid();
	});
	
	WASP_WIDGET.triggerDateStyleWithYMD("#raiseBeginDate");
	$("#raiseBeginDate").on("change", function(){
		$(this).valid && $(this).valid();
	});
	
	WASP_WIDGET.triggerDateStyleWithYMD("#raiseEndDate");
	$("#raiseEndDate").on("change", function(){
		$(this).valid && $(this).valid();
	});
	
	WASP_WIDGET.triggerDateStyleWithYMD("#prjBeginDate");
	$("#prjBeginDate").on("change", function(){
		$(this).valid && $(this).valid();
	});
	
	WASP_WIDGET.triggerDateStyleWithYMD("#prjEndDate");
	$("#prjEndDate").on("change", function(){
		$(this).valid && $(this).valid();
	});
	
	$("#hotNewsAddForm").validate({
		focusCleanup : true
	});
	
}

/**
 * 拓展方法
 */
HOT_NEWS_ADD.prototype.expand = function(){
	var self = this;
	
	self.validate = function() {
		$("#managerId").rules("remove");
		$("#prjName").rules("remove");
		$("#prjStatus").rules("remove");
		$("#runMode").rules("remove");
		$("#profitMode").rules("remove");
		$("#prjTerm").rules("remove");
		$("#startInvestAmount").rules("remove");
		$("#raiseScale").rules("remove");
		$("#riskLevel").rules("remove");
		$("#raiseBeginDate").rules("remove");
		$("#raiseEndDate").rules("remove");
		$("#prjBeginDate").rules("remove");
		$("#prjEndDate").rules("remove");
		$("#compref").rules("remove");
		$("#remark").rules("remove");
		
		$("#managerId").rules("add", {
			required : true, messages: {required: "请选择管理人"}
		});
		$("#prjName").rules("add", {
			required : true, maxlength4Byte: 500 , messages: {required: "请填写产品名称", maxlength4Byte:"产品名称不能大于500个字符"}
		});
		$("#prjStatus").rules("add", {
			required : true, messages: {required: "请选择产品状态"}
		});
		$("#runMode").rules("add", {
			required : true, messages: {required: "请选择运作模式"}
		});
		$("#profitMode").rules("add", {
			required : true, messages: {required: "请选择收益模式"}
		});
		$("#prjTerm").rules("add", {
			required : true, isPositiveNum: true, messages: {required: "请填写产品期限（月）", isIntGtZero: "产品期限必须是大于0的整数"}
		});
		$("#startInvestAmount").rules("add", {
			required : true, fmtNum152: true, messages: {required: "请填写起投金额（元）", isNoNegaNum: "起投金额长度最多13位整数加2位小数"}
		});
		$("#raiseScale").rules("add", {
			required : true, fmtNum152: true, messages: {required: "请填写募集规模（元）", isNoNegaNum: "募集规模长度最多13位整数加2位小数"}
		});
		$("#riskLevel").rules("add", {
			required : true, messages: {required: "请选择风险等级"}
		});
		$("#raiseBeginDate").rules("add", {
			required : true, messages: {required: "请选择募集起始日期"}
		});
		$("#raiseEndDate").rules("add", {
			required : true, messages: {required: "请选择募集结束日期"}
		});
		$("#prjBeginDate").rules("add", {
			required : true, messages: {required: "请选择产品成立日期"}
		});
		$("#prjEndDate").rules("add", {
			required : true, messages: {required: "请选择产品结束日期"}
		});
		$("#compref").rules("add", {
			required : true, maxlength4Byte: 500, messages: {required: "请填写业绩报酬计提基准/单位净值", maxlength4Byte: "业绩报酬计提基准/单位净值不能大于500个字符"}
		});
		$("#remark").rules("add", {
			maxlength4Byte: 4000 , messages: {maxlength4Byte:"备注不能大于4000个字符"}
		});
	};
	
	self.submitForm = function() {
		SubmitAndPreventSecond("hotNewsAddForm",function() {
			self.validate();
			
			if(!$("form[name='hotNewsAddForm']").valid()) {
				toastr.warning('', '请完善信息');
				return false;
			}
			
			if($("#raiseEndDate").val() < $("#raiseBeginDate").val()) {
				toastr.warning('', '募集结束日期应该大于起始日期');
				return false;
			}
			
			if($("#prjEndDate").val() < $("#prjBeginDate").val()) {
				toastr.warning('', '产品结束日期应该大于起始日期');
				return false;
			}
			
			$('#hotNewsAddForm').attr('action', PATH_PREFIX + "insertNewsInfoHot.do");
			
			return true;
		}, true);
	};
}
